package com.blue.integration.spring.bean;

import com.blue.core.auth.AESUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * 属性文件解密
 *
 * @author zhengjin
 * @since 1.0 2018年12月14日
 */
public class EncryptionPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer
{
	private static Logger logger = LoggerFactory.getLogger(EncryptionPropertyPlaceholderConfigurer.class);
	public static final String ENC = "enc:";
	public static final String KEY = "password";
	
	public EncryptionPropertyPlaceholderConfigurer()
	{
	}

	@Override
	protected String convertProperty(String propertyName, String propertyValue)
	{
		String value = propertyValue;
		if (value.startsWith(ENC))
		{
			logger.info("key[{}] - value[{}] 需要解密", propertyName, value);
			value = AESUtil.decrypt(KEY, value.substring(ENC.length()));
		}

		return value;
	}

}
